var vm = new Vue({
	el: '#app',
	data: {
		user: '',
		enums: {
			active: '',
			userLevel: {
				1: "注册用户",
				2: "普通推广员",
				3: "黄金推广员",
				4: "铂金推广员"
			}
		},
		// 控制显示与隐藏的字段
		show: {
			lockDay: 0,
		},
		search: {
			parentUserPhone: '',
			parentUserId: null
		},
	},
	methods: {
		/**
		 * 重置搜索栏
		 * @returns
		 */
		reset: function() {
			vm.search.parentUserPhone = "";
			vm.search.parentUserId = '';
		},
		/**
		 * 设置激活状态
		 */
		setActiveStatus: function() {

			var id = getCheckId();
			if (!id || id == null) {
				layer.msg("请选择一条记录！");
				return;
			}
			layer.open({
				type: 1,
				area: ['500px', '250px'],
				fix: false,
				btn: ['确定', '取消'],
				maxmin: true,
				shade: 0.4,
				title: '用户激活设置',
				success: function(layero, index) {
					var status = getRowData().active;
					$(layero).find('input[name="active"][value="' + status + '"]').attr("checked", true);
				},
				content: $('#activeStatusForm').html(),
				yes: function(index, layero) {
					var activeStatus = $(layero).find('input[name="active"]:checked').val();
					var activeRemark = $(layero).find('#activeRemark').val();
					$.post(baseURL + 'user/active', {
						"id": id,
						"active": activeStatus,
						"activeRemark": activeRemark
					}, function(data) {
						if (data.code === 0) {
							layer.msg('激活状态设置成功！');
							layer.close(index);
							search(false);
						} else {
							layer.alert(data.msg);
						}
					});
				}
			});

		},
		
		// 通用方法，控制div的显示与隐藏
		showControl(key, flag) {
			vm.show[key] = flag;
		},
		initTable: function() {
			// 表格数据请求地址
			var ajaxUrl = baseURL + 'user/list?virtualFlag=0';
			// 配置表头
			var arr = [{
					"data": "id"
				},
				{
					"data": "phone"
				},
				{
					"data": 'userLevel',
					"render": function(data, type, row) {
						if (data == null || data == '') return '';
						return vm.enums.userLevel[data];
					}
				},
				{
					"data": 'userVip',
					"render": function(data, type, row) {
						return data == 0 ?'普通用户':'vip';
					}
				},
				{
					"data": "nickName"
				},
				{
					"data": "parentUserId"
					
				},
				{
					"data": "active",
					"render": function(data, type, row) {
						return data == 1 ?'激活':'冻结';
					}
				},
				{
					"data": "regTime"
				},
				{
					"data": null,
					"render": function(data, type, row) {
						return data.appId + '/' + data.channel;
					}
				}
			];
			// 初始化表格
			TABLE.init(ajaxUrl, arr);
		},
		/**
		 * 打开用户搜索框
		 */
		openUserSearch: function() {

			layer.open({
				type: 2,
				area: ['900px', '480px'],
				fixed: false, //不固定
				maxmin: true,
				btn: ['确定', '取消'],
				title: "选择用户",
				content: baseURL + 'search/user-search.html',
				yes: function(index, layero) {
					var data = getIframeTableData(layero);
					if (data == null) {
						layer.msg('请选择至少一条记录！');
					} else {
						vm.search.parentUserPhone = data.phone;
						vm.search.parentUserId = parseInt(data.id);
						layer.close(index);
					}
				}
			});
		}
	},
	mounted() {
		this.initTable();
	}
})



